package com.ali.controller;

import com.ali.common.Response;
import com.ali.service.Resilience4jService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.CompletableFuture;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private Resilience4jService resilience4jService;

    /**
     * Resilience4j服务熔断
     */
    @GetMapping(value = "/resilience4j/circuitbreaker")
    public Response<String> circuitBreaker(@RequestParam Map<String, Object> param) {
        return resilience4jService.circuitBreaker(param);
    }

    /**
     * Resilience4j服务隔离，信号量模式
     */
    @GetMapping(value = "/resilience4j/bulkhead/semaphore")
    public Response<String> bulkheadSemaphore(@RequestParam Map<String, Object> param) {
        return resilience4jService.bulkheadSemaphore(param);
    }

    /**
     * Resilience4j服务隔离，线程池模式
     */
    @GetMapping(value = "/resilience4j/bulkhead/threadpool")
    public CompletableFuture<String> bulkheadThreadPool(@RequestParam Map<String, Object> param) {
        return resilience4jService.bulkheadThreadPool(param);
    }

    /**
     * Resilience4j服务限流
     */
    @GetMapping(value = "/resilience4j/ratelimiter")
    public Response<String> rateLimiter(@RequestParam Map<String, Object> param) {
        return resilience4jService.rateLimiter(param);
    }
}